import http from '@/utils/http/axios';
import {RequestEnum, ContentTypeEnum} from '@/enums/httpEnum'

enum Api {
  fetchAdminList = '/mall-admin/admin/list',
  updateStatus = '/mall-admin/admin/updateStatus',
  register = '/mall-admin/admin/register',
  getRoles = '/mall-admin/admin/role',
  updateRoles = '/mall-admin/admin/role/update',
  fetchAllRoles = '/mall-admin/role/listAll',
  updateUser = '/mall-admin/admin/update',
  deleteUser = '/mall-admin/admin/delete'
}

/**
 * 获取用户列表
 * @param params
 */
export function getAdminAccount(params) {
  return http.request({
    url: Api.fetchAdminList,
    method: RequestEnum.GET,
    params
  });
}

/**
 * 修改帐号状态
 * @param params 
 */
export function updateStatus(id, params) {
  return http.request({
    url: [Api.updateStatus, id].join('/'),
    method: RequestEnum.POST,
    params
  }, {
    successMessageText: '修改成功'
  })
}

// 添加用户
export function addAccount(params) {
  return http.request({
    url: Api.register,
    method: RequestEnum.POST,
    headers: {
      'Content-type': ContentTypeEnum.JSON
    },
    params
  }, {
    isParseToJson: true,
    successMessageText: '操作成功'
  })
}

/**
 * 获取用户的角色信息
 */
export function getAccountRoleInfo(id) {
  return http.request({
    url: [Api.getRoles, id].join('/'),
    method: RequestEnum.GET
  })
}

/**
 * 获取用户的角色列表
 */
export function getAccountRoles() {
  return http.request({
    url: Api.fetchAllRoles,
    method: RequestEnum.GET
  })
}

/**
 * 给用户分配角色
 */
export function updateAccountRoles(params) {
  return http.request({
    url: Api.updateRoles,
    method: RequestEnum.POST,
    params
  }, {
    successMessageText: '操作成功'
  })
}

/**
 * 更新指定用户信息
 * @param id 
 * @param params 
 */
export function updateAccountInfo(id, params) {
  return http.request({
    url: [Api.updateUser, id].join('/'),
    method: RequestEnum.POST,
    headers: {
      'Content-type': ContentTypeEnum.JSON
    },
    params
  }, {
    isParseToJson: true,
    successMessageText: '操作成功'
  })
}

/**
 * 删除指定用户信息
 */
export function deleteAccount(id) {
  return http.request({
    url: [Api.deleteUser, id].join('/'),
    method: RequestEnum.POST
  }, {
    successMessageText: '删除成功'
  })
}